home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / 8250.zip / 8250.DOC next >
Text File  |  1988-06-27  |  19KB  |  368 lines

  1. Note: References to Stargate are specific to that multi serial port board.
  2.       References to the 8250 apply to all 8250 UART chips. Some comments may
  3.       indicate that a specific condition is needed a a specific serial board.
  4.  
  5.  
  6. Below are some UNTESTED routines which I believe will help in setting
  7. some com parameters. These routines have not reached the debug stage,
  8. so no gaurantees. I was originally writting this for a complex system
  9. which would address several serial port locations, port[port_num] in the
  10. routines below refer to the base port address of the specific 8250 chip.
  11. That project has been put on hold at the present time. I present this
  12. information to the BBS comunity because recent programs have produced
  13. 8250 transfer rates at speeds of 115K+ baud, much above documented
  14. transfer rates which are deemed realistic. These programs appear to function
  15. without any adverse conditions at these rates. So, I hope all hackers can
  16. delight in the information which follows.
  17. These routines were written in TURBOC Ver 1.5 and are given only to show
  18. how I believe setting the parameters could be done. Again, These routines
  19. have not been tested or debugged.
  20.  
  21.  
  22. STARGATE OC8000 SETTINGS
  23.  
  24.      PORT ADDRESSES      HEX LOCATION 1      HEX LOCATION 2
  25.      PORT 1                   180                 3F8  (Normally COM1)
  26.      PORT 2                   188                 2F8  (Normally COM2)
  27.      PORT 3                   190                 280
  28.      PORT 4                   198                 288
  29.      PORT 5                   1A0                 290
  30.      PORT 6                   1A8                 298
  31.      PORT 7                   1B0                 2A0
  32.      PORT 8                   1B8                 2A8
  33.  
  34.      Interrupt
  35.      Status Register          580                 7F8
  36.  
  37.      HARDWARE INTERRUPT SET TO IRQ3 (used by COM2 devices) OR
  38.      HARDWARE INTERRUPT SET TO IRQ4 (used by COM1 devices) OR
  39.      HARDWARE INTERRUPT IRQ2 MAY BE USED IF IT IS NOT TAKEN BY ANOTHER
  40.           DEVICE, THUS PRESERVING COM1,COM2 PORTS AS NORMAL.
  41.      HIGHER IRQ SETTINGS NOT RECOMMENDED SINCE THEY HAVE LOWER PRIORITIES
  42.      AND/OR MAY BE TAKEN BY OTHER DEVICES. A LIST OF HARDWARE IRQ
  43.      ASSIGNMENTS IN DOS ARE SHOWN BELOW.
  44.  
  45.      Switch Settings on OC8000 board:
  46.           ( Set one of the switches 1-6 to on to set IRQ# )
  47.           ( Lowest IRQ has highest interrupt priority.    )
  48.  
  49.           Dip Switch 1   Location 1          Location 2     IRQ
  50.  
  51.                     8    OFF                 ON
  52.                     7    ON                  ON             SEE DOC
  53.                       (--------- CHOOSE ONE ONLY --------)
  54.                     6    ON SETS OFF DISABLES IRQ           7
  55.                     5    ON SETS OFF DISABLES IRQ           6
  56.                     4    ON SETS OFF DISABLES IRQ           5
  57.                     3    ON SETS OFF DISABLES IRQ           4
  58.                     2    ON SETS OFF DISABLES IRQ           3
  59.                     1    ON SETS OFF DISABLES IRQ           2
  60.  
  61.           Dip Switch 2 sets number of uarts in last 4 positions.
  62.                     OC 8000 board with # UARTS;         DS2 SWITCH POS.
  63.                     UART LOCATION      NUM             1    2    3    4
  64.                                         4              ON   ON   ON   ON
  65.                     TOP                 5              OFF  ON   ON   ON
  66.                     SECOND FROM TOP     6              OFF  OFF  ON   ON
  67.                     SECOND FROM BOTTOM  7              OFF  OFF  OFF  ON
  68.                     BOTTOM              8              OFF  OFF  OFF  OFF
  69.  
  70.           In looking at the OC8000 board, these switches appear to fix pin
  71.           30 of the 8250 chip to ground. This is the interrupt pin that goes
  72.           high when any of the allowed IER interrupts occur on the 8250.
  73.           Grounding this pin effectively disables any hardware interrupts
  74.           being sent to the CPU via the Stargate Interrupt Status Register.
  75.  
  76. -------------------------------------------------------------------------------
  77. == General IBM Hardware interrupt locations. PC-XT and AT ==
  78. Hardware Interrupt Vector memory locations and number: DOS 2.X - 3.X
  79. IRQ                                   Number
  80.                                   (hex) - (Decimal)
  81. IRQ0 System Timer Tick Attention - 0x20    - 8
  82. IRQ1 Keyboard Attention          - 0x24    - 9
  83. IRQ2 Reserved for future use     - 0x28    - 10
  84. IRQ3 Com2 Attention              - 0x2C    - 11
  85. IRQ4 Com1 Attention              - 0x30    - 12
  86. IRQ5 Harddisk Attention          - 0x34    - 13
  87. IRQ6 Disk controller Attention   - 0x38    - 14
  88. IRQ7 Parallel Printer Attention  - 0x3C    - 15
  89. -------------------------------------------------------------------------------
  90. ===============================================================================
  91.  
  92.      Detailed 8250A register locations for performing IO.
  93.  
  94.      BASE+0    TX CHARACTER BUFFER      if DLAB=0
  95.                --------------------------------------------------------------
  96.  
  97.      BASE+0    LSB DIVSOR LATCH         if DLAB=1
  98.                --------------------------------------------------------------
  99.  
  100.      BASE+0    RX CHARACTER BUFFER      if DLAB=0
  101.                --------------------------------------------------------------
  102.  
  103.      BASE+1    MSB DIVSOR LATCH         if DLAB=1
  104.                --------------------------------------------------------------
  105.  
  106.      BASE+1    INTERRUPT ENABLE REG     if DLAB=0 (IER)
  107.                ENABLES FOUR 8250 INTERRUPT TYPES TO SEPERATELY ACTIVATE
  108.                THE CHIP (INTRPT) OUTPUT SIGNAL. A 0 IN BITS 0-3 DEACTIVATE
  109.                ALL INTERRUPTS, AND PLACING A 1 IN ANY BIT 0-3 ACTIVATES
  110.                THE INTERRUPT.
  111.                D7=0
  112.                D6=0
  113.                D5=0
  114.                D4=0
  115.                D3= ENABLE MODEM STATUS INTERRUPT
  116.                D2= ENABLE RECEIVE LINE STATUS INTERRUPT
  117.                D1= ENABLE TX HOLDING REGISTER INTERRUPT
  118.                D0= ENABLE RECEIVE DATA AVAILABLE INTERRUPT
  119.                --------------------------------------------------------------
  120.  
  121.      BASE+2    INTERRUPT ID REGISTER    (IIR)
  122.                D7=0
  123.                D6=0
  124.                D5=0
  125.                D4=0
  126.                D3=0
  127.                D2-D1     INDICATES THE HIGHEST 8250A INTERNAL INTERRUPT
  128.                          PENDING. SUMMARIZED BELOW.
  129.                D0=       0=INDICATES INTERRUPT PENDING.
  130.                          1=INDICATES NO INTERRUPT PENDING.
  131.  
  132.                BIT 2 1 0 PRIORITY  INTERRUPT           INTERRUPT      RESET
  133.                                    TYPE                SOURCE         CONTROL
  134.                --------------------------------------------------------------
  135.                    1 1 0  HIGHEST  RX LINE STATUS      OVERRUN,       READ
  136.                                                        PARITY,        LINE
  137.                                                        FRAMEING       STATUS
  138.                                                        ERRORS,        REGISTER
  139.                                                        OR BREAK
  140.                                                        INTERRUPT
  141.                --------------------------------------------------------------
  142.                    1 0 0 SECOND    RECEIVED            RECEIVER       READ
  143.                                    DATA                DATA           RECEIVER
  144.                                    AVAILABLE           READY          BUFFER
  145.                                                                       REGISTER
  146.                --------------------------------------------------------------
  147.                    0 1 0 THIRD     TX HOLDING          TX HOLDING     READ
  148.                                    REGISTER IS         REGISTER IS    (IIR) IF
  149.                                    EMPTY               EMPTY          SOURCE OF
  150.                                                                       INTERRUPT
  151.                                                                          OR
  152.                                                                       WRITE TO
  153.                                                                       TX HOLDING
  154.                                                                       REGISTER
  155.                -----------------------------------------------------------------
  156.                    0 0 0 FOURTH    MODEM STATUS        CTS,DSR,       READ
  157.                                                        RING           MODEM
  158.                                                        INDICATOR,     STATUS
  159.                                                        OR RECEIVE     REGISTER
  160.                                                        LINE SIGNAL
  161.                                                        DETECT
  162.                --------------------------------------------------------------
  163.  
  164.      BASE+3    LINE CONTROL REG         (LCR)
  165.                DLAB state=bit 7
  166.                D7;  DLAB
  167.                D6;  0=break disabled.
  168.                     1=break  enabled.
  169.                D5;  0=parity disabled.
  170.                     1=parity enabled.
  171.                D4;  0=odd parity.
  172.                     1=even parity.
  173.                D3;  0=no parity.
  174.                     1=parity.
  175.                D2;  0=1 stop bit.
  176.                     1=2 stop bits if bits/char > 5, else 1.5 stop bits.
  177.                D1-0;00=5 bits/char
  178.                     01=6 bits/char
  179.                     10=7 bits/char
  180.                     11=8 bits/char
  181.  
  182.                --------------------------------------------------------------
  183.  
  184.      BASE+4    MODEM CONTROL REG        (MCR)
  185.  
  186.                IMPORTANT:
  187.                Bit 3 must be 0 to allow for IRQ in the Interrupt Enable Reg.
  188.                to take place.
  189.  
  190.                D7=0;
  191.                D6=0;
  192.                D5=0;
  193.                D4;  Loopback for internal testing of the 8250 chip.
  194.                     In diagnostic mode when set to 1;
  195.                     Diagnostics off when reset to 0 (Normal Operation);
  196.                D3;  Controls User Designated OUT2 signal output.
  197.                     (8250 UART PIN 34)
  198.                     (Not used on Stargate Card OC8000)
  199.                     (Must be 0 to allow IER interrupts on IBM cards,
  200.                      don't know about others.)
  201.                     When set to 1, OUT2 output forced to logic 0.
  202.                     When reset to 0, OUT2 output forced to logic 1.
  203.                D2;  Controls User Designated OUT1 signal output.
  204.                     (8250 UART PIN 34)
  205.                     (Not used on Stargate Card OC8000)
  206.                     When set to 1, OUT1 output forced to logic 0.
  207.                     When reset to 0, OUT1 output forced to logic 1.
  208.                D1;  Controls RTS output.
  209.                     (8250 UART PIN 32, RS232C PIN 4)
  210.                     (Available on Stargate OC8000 Port 1 only)
  211.                     When set to 1, RTS output forced to logic 0.
  212.                     When reset to 0, RTS output forced to logic 1.
  213.                D0;     Controls DTR output.
  214.                     (8250 UART PIN 33, RS232C PIN 20)
  215.                     (Available on Stargate OC8000 Port 1 only)
  216.                     When set to 1, DTR output forced to logic 0.
  217.                     When reset to 0, DTR output forced to logic 1.
  218.  
  219.                --------------------------------------------------------------
  220.  
  221.      BASE+5    LINE STATUS REG          (LSR)     LOGIC STATES;
  222.                D7=0
  223.                D6=TX SHIFT REG EMPTY(TSRE)        1=TSRE IDLE
  224.                                                   0=DATA TRANSFER FROM
  225.                                                     THRE TO TSRE.
  226.                D5=TX HOLDING REG EMPTY (THRE)     READY TO EXCEPT NEW CHAR
  227.                                                   1=ISSUES IRQ TO CPU, SET
  228.                                                     WHEN CHAR IS TRANSFERRED
  229.                                                     FROM THRE TO TSRE.
  230.                                                   0=RESET WHEN THRE LOADED
  231.                                                     FROM CPU.
  232.                (Bits 1-4 are error conditions that produce a Receiver
  233.                 Line Status Interrupt when their conditions are detected)
  234.  
  235.                D4=BREAK INTERRUPT (BI)            1=RECEIVED DATA HELD LONGER
  236.                                                     THAN SPACING STATE(Logic 0)
  237.                                                     FOR LONGER THAN FULL WORD
  238.                                                     TRANSMIT TIME.
  239.                D3=FRAMING ERROR (FE)              1=INDICATES INVALID STOP
  240.                                                     BIT, STOP BIT DETECTED AS
  241.                    PIN 31 8250A                     0 (SPACING LEVEL) FOLLOWING
  242.                                                     LAST DATA OR PARITY BIT.
  243.                D2=PARITY ERROR (PE)               1=INDICATES WRONG PARITY AS
  244.                                                     SELECTED IN LINE CONTROL
  245.                    PIN 34 8250A                     REG. RESET BY HAVING CPU
  246.                                                     READ LINE STATUS REGISTER.
  247.                D1=OVERRUN ERROR (OE)              1=DATA IN RECEIVE BUFFER REG
  248.                RTS PIN 4 RS232                      NOT READ BY CPU BEFORE NEXT
  249.                    PIN 32 8250A                     CHAR TRANSFERRED INTO THE
  250.                                                     RECEIVE BUFFER REG, THUS
  251.                                                     DESTROYING PREVIOUS CONTENTS.
  252.                                                     RESET BY READING LINE STATUS
  253.                                                     REGISTER.
  254.                D0=DATA READY (DR)                 1=INDICATES A COMPLETE CHARACTER
  255.                DTR PIN 20 RS232                     HAS BEEN RECEIVED AND PLACED
  256.                    PIN 33 8250A                     INTO THE RECEIVE BUFFER REG.
  257.                                                     RESET BY READING (RBR) OR
  258.                                                     WRITING A 0 TO THIS BIT BY CPU.
  259.                --------------------------------------------------------------
  260.                                                      PINS ON - RS232    8250A
  261.      BASE+6    MODEM SATUS REG          (MSR)
  262.                D7= (RLSD) RECEIVE LINE SIGNAL DETECT             8
  263.                D6= (RI) RING INDICATOR                           22
  264.                D5= (DSR) DATA SET READY                          6
  265.                D4= (CTS) CLEAR TO SEND                           5
  266.                (The bits below are 1 if state of bits above changed since
  267.                 the last reading of this register.)
  268.                D3= (DRLSD) DELTA RECIEVE LINE SIGNAL DETECT                38
  269.                D2= (TERI) TRAILING EDGE RING INDICATOR                     39
  270.                D1= (DDSR) DELTA DATA SET READY                             37
  271.                D0= (DCTS) DELTA CLEAR TO SEND                              36
  272.  
  273.      ------------------------------------------------------------------------
  274.      Summary of 8250A register locations for performing IO.
  275.      BASE+0    TX CHARACTER BUFFER      if DLAB=0
  276.      BASE+0    LSB DIVSOR LATCH         if DLAB=1
  277.      BASE+0    RX CHARACTER BUFFER      if DLAB=0
  278.      BASE+1    MSB DIVSOR LATCH         if DLAB=1
  279.      BASE+1    INTERRUPT ENABLE REG     if DLAB=0 (IER)
  280.      BASE+2    INTERRUPT ID REGISTER    (IIR)
  281.      BASE+3    LINE CONTROL REG         (LCR)
  282.      BASE+4    MODEM CONTROL REG        (MCR)
  283.      BASE+5    LINE STATUS REG          (LSR)
  284.      BASE+6    MODEM SATUS REG          (MSR)
  285.      ------------------------------------------------------------------------
  286.  
  287.      NOTE: Very little information was found on the 8259 interrupt controller
  288.            chip. What was found and could be verified to the best of my
  289.            knowledge is given below.
  290.  
  291. 8259 Interrupt Controller Notes:
  292.      Acoording to research information,
  293.      Port Location 0x20 MUST BE SENT A 0x20 TO INDICATE AN EOI.
  294.      However in a review of BIOS async routines, no such EOI is sent.
  295.      It is used however to indicate a state change on the keyboard
  296.      interrupt BIOS routine.
  297.  
  298.      Port Location 0x21 is the IRQ0-IRQ7 Hardware Interrupt Mask.
  299.           0=Interrupt Enabled, 1=Interrupt Disabled.
  300.  
  301. **************************************************************************/
  302.  
  303. #define SET_DLAB1 outportb(port[port_num]+3,(0x80|inport(port[port_num]+3)))
  304. #define SET_DLAB0 outportb(port[port_num]+3,(0x7F&inport(port[port_num]+3)))
  305. #define CLOCK_SPEED 1843200
  306.  
  307. /**** Set Baud Rate
  308. void set_baud (short int port_num)
  309.      Sets the baud rate of an 8250 chip at the base address
  310.      on port_num.
  311.      Buad rate errors are minimal at baud rates <= 9600.
  312. ****/
  313. void set_baud (short int port_num)
  314. {
  315.      unsigned short int divisor;
  316.  
  317.      divisor=CLOCK_SPEED/(baud[port_num]*16);
  318.      SET_DLAB1;
  319.      outport(port[port_num],divisor);
  320.      SET_DLAB0;
  321.      return;
  322. } /* end set_baud() */
  323.  
  324.  
  325. /**** Set frameing parameters on communications port.
  326. void set_frame(short int port_num)
  327.      Sets the parity, bits/character, and number of stop bits.
  328.      port_num is used to get pointer to base address of 8250 chip.
  329.      Meaning of frame bits.
  330.           D7;  DLAB
  331.           D6;  0=break disabled.
  332.                1=break  enabled.
  333.           D5;  0=parity disabled.
  334.                1=parity enabled.
  335.           D4;  0=odd parity.
  336.                1=even parity.
  337.           D3;  0=no parity.
  338.                1=parity.
  339.           D2;  0=1 stop bit.
  340.                1=2 stop bits if bits/char > 5, else 1.5 stop bits.
  341.           D1-0;00=5 bits/char
  342.                01=6 bits/char
  343.                10=7 bits/char
  344.                11=8 bits/char
  345. ****/
  346. void set_frame(short int port_num)
  347. {
  348. unsigned char f_byte,temp;
  349. int i;
  350.      SET_DLAB0;
  351.      f_byte=0;
  352.  
  353.      /* set parity */
  354.      if (parity[port_num] =='E' | parity[port_num]=='e') f_byte=0x3F;
  355.      if (parity[port_num] =='O' | parity[port_num]=='o') f_byte=0x2F;
  356.  
  357.      /* set word length */
  358.      temp=wordlen[port_num]-5;
  359.      f_byte |=temp;
  360.  
  361.      /* set stop bits */
  362.      if(!(2-stopbits[port_num])) f_byte |='\04';
  363.  
  364.      /* configure port */
  365.      outportb(port[port_num]+3,f_byte);
  366. return;
  367. } /* end set_frame() */
  368.